<template>
  <div class="app-container">
    <!--    <el-button   class="filter-item marginRB10" type="primary" icon="el-icon-plus" @click="handleCreate()">添加</el-button>-->
    <el-input class="marginRB10" v-model="listQuery.order_no" placeholder="请输入订单编号" style="width:200px;"
              clearable></el-input>
    <el-input class="marginRB10" v-model="listQuery.user_code" placeholder="请输入用户编号" style="width:200px;"
              clearable></el-input>
    <el-input class="marginRB10" v-model="listQuery.ulisence_id" placeholder="请输入用户资质id" style="width:200px;"
              clearable></el-input>
    <el-button type="primary" @click="searchList" icon="el-icon-search"   class="marginRB10">搜索</el-button>

    <el-table ref="dataList" :data="menuList" style="margin-bottom: 20px;" row-key="id" border>
      <el-table-column prop="comment_id" label="评论id"></el-table-column>
      <el-table-column prop="user_id" label="评论人用户id"></el-table-column>
      <el-table-column prop="uid" label="被评论用户id"></el-table-column>
      <el-table-column prop="ulisence_id" label="用户资质id"></el-table-column>
      <el-table-column prop="add_time" label="添加时间"></el-table-column>
      <el-table-column prop="order_id" label="订单id"></el-table-column>
      <el-table-column prop="lisence_id" label="资质id"></el-table-column>
      <el-table-column prop="content" label="评论内容"></el-table-column>
      <el-table-column prop="score" label="评分"></el-table-column>
      <el-table-column prop="grade" label="等级">
        <template slot-scope="scope">
          {{ scope.row.grade === 1 ? '好评' : '' }}
          {{ scope.row.grade === 2 ? '中评' : '' }}
          {{ scope.row.grade === 3 ? '差评' : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          {{ scope.row.status === 1 ? '正常' : '' }}
          {{ scope.row.status === 2 ? '待审核' : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="mark" label="是否是第一次下单">
        <template slot-scope="scope">
          {{ scope.row.mark === 1 ? '不是' : '' }}
          {{ scope.row.mark === 2 ? '是' : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="service_grade" label="服务满意度">
        <template slot-scope="scope">
          {{ scope.row.service_grade === 1 ? '满意' : '' }}
          {{ scope.row.service_grade === 2 ? '一般' : '' }}
          {{ scope.row.service_grade === 3 ? '不满意' : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="special_grade" label="专业度满意度">
        <template slot-scope="scope">
          {{ scope.row.special_grade === 1 ? '满意' : '' }}
          {{ scope.row.special_grade === 2 ? '一般' : '' }}
          {{ scope.row.special_grade === 3 ? '不满意' : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="experience_grade" label="体验满意度"></el-table-column>
      <el-table-column prop="order_no" label="订单号"></el-table-column>
      <el-table-column prop="nickname" label="评论人用户昵称"></el-table-column>
      <el-table-column prop="user_code" label="评论人用户编号"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          {{ scope.row.status === 1 ? '正常' : '暂停' }}
        </template>
      </el-table-column>
      <!--      <el-table-column min-width="180" label="操作">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleUpdate(scope.row)" plain>编辑</el-button>-->
      <!--          <cus-del-btn @ok="handleDelete(scope.row)"></cus-del-btn>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <cus-pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.perPage"
                    @pagination="getList"/>

    <el-dialog v-dialogDrag :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible"
               @close="handleDialogClose">
      <el-form ref="dataForm" :rules="rules" :model="form" label-position="right" label-width="120px"
               style="width: 400px; margin: 0 auto;">
        <el-form-item label="资质名称" prop="lisence_name">
          <el-input v-model="form.lisence_name" placeholder="请输入资质名称"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="dialogFormVisible = false">
          取 消
        </el-button>
        <el-button type="primary" @click="submitForm()">
          确 认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {deleteData, listData} from '@/api/qualifications/qualificationsComment'

export default {
  data() {
    return {
      listLoading: true,
      total: 0,
      listQuery: {
        page: 1,
        perPage: 10,
        order_no: undefined,
        user_code: undefined,
        ulisence_id: undefined,
      },
      menuList: [],
      dialogFormVisible: false,
      dialogStatus: '',
      titleMap: {
        update: '编辑',
        create: '增加'
      },
      form: {
        lisence_id: undefined,
      },
      rules: {
        lisence_name: [{required: true, message: '请输入资质名称', trigger: 'blur'}],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 点击查询
    searchSubmit() {
      this.listQuery.page = 1;
      this.getList()
    },
    getList() {
      this.listLoading = true
      for (let key in this.listQuery) {
        this.listQuery[key] = this.listQuery[key] === "" ? undefined : this.listQuery[key]
      }
      listData(this.listQuery).then(response => {
        this.menuList = response.data.list
        this.total = response.data.meta.total;
        this.listLoading = false
      })
    },
    /* 搜索 */
    searchList() {

    },
    handleCreate(row) {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
    },
    handleUpdate(row) {
      this.form = []
      this.form.lisence_id = row.lisence_id

      this.dialogStatus = 'update'
      this.dialogFormVisible = true

      this.form = Object.assign({}, this.form)
    },
    handleDelete(row) {
      let data = {ids: row.lisence_id}
      deleteData(data).then(response => {
        if (response.code === 200) {
          this.getList()
          this.$notify({
            type: 'success',
            message: '操作成功',
            position: 'bottom-right',
            showClose: false,
            duration: 3000
          });
        }
      })
    },
    submitForm() {
      this.$refs['dataForm'].validate(valid => {
        if (valid && this.dialogStatus === 'create') {
          let formData = new FormData();
          for (let item in this.form) {
            this.form[item] === undefined ? '' : formData.append(item, this.form[item]);
          }
          saveData(formData).then(response => {
            if (response.code === 200) {
              this.getList()
              this.$notify({
                type: 'success',
                message: '操作成功',
                position: 'bottom-right',
                showClose: false,
                duration: 3000
              });
              this.dialogFormVisible = false
            } else {
              this.$message({
                message: response.message,
                type: 'error'
              });
            }
          })
        } else if (valid && this.dialogStatus === 'update') {
          let formData = new FormData();
          for (let item in this.form) {
            this.form[item] === undefined ? '' : formData.append(item, this.form[item]);
          }
          updateData(formData).then(response => {
            if (response.code === 200) {
              this.getList()
              this.$notify({
                type: 'success',
                message: '操作成功',
                position: 'bottom-right',
                showClose: false,
                duration: 3000
              });
              this.dialogFormVisible = false
            } else {
              this.$message({
                message: response.message,
                type: 'error'
              });
            }
          })
        }
      })
    },
    resetForm() {
      this.form = {
        lisence_id: undefined,
      }
    },
    // 监听dialog关闭时的处理事件
    handleDialogClose() {
      if (this.$refs['dataForm']) {
        this.$refs['dataForm'].clearValidate() // 清除整个表单的校验
      }
    }
  }
}
</script>
